<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="static/plugins/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .btn-outline-black {
            color: black;
            background-color: transparent;
            background-image: none;
            border-color: black;
            border-radius: 30px !important;

        }

        .button-group {
            display: flex;
            gap: 5%;

        }
    </style>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container">
        <div class="navbar-header">
            <a class="navbar-brand" href="ClientMain.html">图书管理系统</a>
        </div>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="AssistantBookList.html">图书馆</a></li>
            <li><a href="AssistantOrderList.html">借阅列表</a></li>
            <li><a href="AssistantSellList.html">购买记录</a></li>
            <li><a href="AssistantAddBook.html">添加书籍</a></li>
            <li><a href="index.html">退出登录</a></li>
        </ul>
    </div>
</nav>
<div class="container" style="width: 400px;margin-top: 10%">
    <form method="post">
        <label class="form-label">修改信息</label>
        <div class="mb-3">
            <div class="input-icon">
                <label class="form-label">书名</label>
                <label>
                    <input class="form-control form-control-rounded" name="name" size="21" type="password">
                </label>
            </div>
            <div class="input-icon">
                <label class="form-label">作者</label>
                <label>
                    <input class="form-control form-control-rounded" name="author" size="21" type="password">
                </label>
            </div>
            <div class="input-icon">
                <label class="form-label">出版商</label>
                <label>
                    <input class="form-control form-control-rounded" name="publisher" size="21" type="password">
                </label>
            </div>
            <div class="input-icon">
                <label class="form-label">价格</label>
                <label>
                    <input class="form-control form-control-rounded" name="price" size="21" type="password">
                </label>
            </div>
            <div class="input-icon">
                <label class="form-label">数量</label>
                <label>
                    <input class="form-control form-control-rounded" name="quantity" size="21" type="password">
                </label>
            </div>
        </div>
        <div class="button-group">
            <input class="btn btn-lg btn-outline-black" id="edit" type="submit" value="修改"/>
            <input class="btn btn-lg btn-outline-black" type="reset" value="重置"/>
        </div>
    </form>
    <div id="message"></div>
</div>
<script src="static/js/jquery.js" type="text/javascript"></script>
<script src="static/plugins/bootstrap-3.4.1-dist/js/bootstrap.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        const urlParams = new URLSearchParams(window.location.search);
        const number = urlParams.get('number');
        $("#edit").click(function (e) {
            e.preventDefault();
            const Name = $("input[name='name']").val();
            const Author = $("input[name='author']").val();
            const Publisher = $("input[name='publisher']").val();
            const Price = $("input[name='price']").val();
            const Quantity = $("input[name='quantity']").val();
            $.ajax({
                url: "BookEditServlet",
                method: "post",
                data: {
                    number: number,
                    name: Name,
                    author: Author,
                    publisher: Publisher,
                    price: Price,
                    quantity: Quantity

                },
                dataType: "json",
                success: function (result) {
                    if (result.msg === "success") {
                        window.location.href = "AssistantBookList.html";
                        console.log(result.message);
                    } else {
                        $('#message').text('修改失败，请稍后重试');
                    }
                },
                error: function () {
                    $('#message').text('服务未连接，请稍后重试');
                }
            });
        });
    });
</script>
</body>
</html>